<template>  
  <div class="classify">
    <router-view></router-view>
    <div class="c-banner">
      <div class="c-title">
        <img src="../../../public/images/logo.svg" alt="" />
      </div>
      <div class="c-banner-bot">
        <div class="c-banner-title">
          <p>探索</p>
          <p>属于你的家居伴侣</p>
        </div>
        <router-link
        to="/search"
        custom
        v-slot="{ href, route, navigate, isActive, isExactActive }"
      >
        <div class="c-search" @click="navigate">
          <img
            src="../../../public/images/classify/classify-search.svg"
            alt=""
          />
        </div>
        </router-link> 
      </div>
    </div>
    <div class="classify-list">
      <van-sidebar v-model="activeKey" @change="onChange">
        <van-sidebar-item v-for="item in dataList" :title="item.name" :key="item.id"/>
      </van-sidebar>
      <div class="classifyContent">
        <div class="classifyList">
          <transition name="van-slide-down">
          <div class="classify_team" v-for="item,index in dataList" :key="item.id" v-if="index===showid">
            <h2>{{item.name}}</h2>
            <ul>
              <router-link :to="`/classify/classifychild/${child.id}`" exact v-for="child in item.children" :key="child.id">
              <!-- <router-link to="/classifychild" exact v-for="child in item.children" :key="child.id"> -->
                <ClassifyLink>
                  <img
                    :src="child.icon"
                    alt=""
                  />
                  <p>{{child.name}}</p>
                </ClassifyLink :isActive="isActive" @click.native="navigate">
              </router-link>
            </ul>
          </div>
          </transition>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Vue from "vue";
import { Sidebar, SidebarItem } from "vant";
import axios from "axios";
import ClassifyLink from "../../components/ClassifyLink.vue";
Vue.use(Sidebar);
Vue.use(SidebarItem);
export default {
  components: {
    ClassifyLink,
  },
  data() {
    return {
      activeKey: 0,
      dataList: [],
      showid:0
    };
  },
  //计算属性 依赖缓存,多对一(即多个影响一个),不支持异步
  computed: {},
  //监控data中的数据变化,不依赖缓存,一对多,支持异步
  watch: {},
  //方法集合
  methods: {
    onChange(index) {
      // Notify({ type: 'primary', message: index });
      this.showid=index;
    },
    async onLoadData() {
      let list = await axios.get(
        "https://www.ikea.cn/api-host/content/catalogs"
      );
      this.dataList = list.data;
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  async mounted() {
    await this.onLoadData();
  },
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang='stylus' scoped>
.classify {
  width: 100%;

  .c-banner {
    width: 100%;
    height: 2.14rem;
    padding: 0.15rem 0.19rem 0 0.3rem;
    background: url('../../../public/images/classify/classify-banner.png') no-repeat 0 0;
    background-size: 100% 100%;

    .c-title {
      width: 0.6rem;
      height: 0.25rem;

      img {
        width: 100%;
      }
    }

    .c-banner-bot {
      display: flex;
      justify-content: space-between;
      padding-top: 0.15rem;

      .c-banner-title {
        color: #FFF;
        font-size: 0.24rem;
        font-weight: 600;
        line-height: 0.34rem;
      }
    }
  }

  .classify-list {
    display: flex;
    border-radius: 0.16rem;
    overflow: scroll;
    margin-top: -0.5rem;
    background-color: #fff;
    height: calc(100vh - 1.64rem);
    padding-bottom 0.5rem
    .van-sidebar {
      // overflow scroll
    }

    .van-sidebar-item--select::before {
      background: transparent;
    }

    .van-sidebar-item {
      font-size: 0.12rem;
      line-height: 0.48rem;
      text-align: center;
      height: 0.48rem;
      padding: 0 0.1rem;
    }

    .van-sidebar-item__text {
      color: #666666;
    }

    .classifyContent {
      padding: 0 0.28rem;
      width: calc(100% - 0.8rem);
      overflow: scroll;

      .classifyList {
        padding-top: 0.4rem;
        background-color: #FFF;

        .classify_team {
          h2 {
            font-size: 0.12rem;
            color: #111;
            text-align: center;
            margin-bottom: 0.2rem;
            font-weight: normal;
          }

          ul {
            display: flex;
            justify-content: space-between;
            width: 100%;
            flex-wrap: wrap;

            li {
              width: 1rem;
              height: 1.05rem;
              text-align: center;
              padding: 0.1rem 0.09rem 0.14rem;

              img {
                width: 0.5rem;
                height: 0.55rem;
              }

              p {
                margin-top: 0.08rem;
                font-size: 0.12rem;
                color: #111111;
              }
            }
          }
        }
      }
    }
  }
}
</style>